package cn.diancan.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import cn.diancan.model.types.CommonType;
import cn.diancan.util.DateUtil;
 

@MappedSuperclass
public class BaseEntity implements Serializable {
     
    /**
     * 
     */
    private static final long serialVersionUID = -1273180229988110492L;
    
    private Long id;
    private String createTime;
    private String modifyTime; 
    private Integer isDelete;

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    @Column(columnDefinition="DATETIME",updatable=false)
    public String getCreateTime(){
        return DateUtil.getMysqlDateTime(createTime);
    } 
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    
    @Column(columnDefinition="DATETIME")
    public String getModifyTime() {
        return DateUtil.getMysqlDateTime(modifyTime);
    }
    public void setModifyTime(String modifyTime) {
        this.modifyTime = modifyTime;
    }
    
    public Integer getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Integer isDelete) {
        this.isDelete = isDelete;
    }
    
    public void init(){
	    this.createTime =DateUtil.currentDateTime();
	    this.modifyTime =DateUtil.currentDateTime();
	    this.isDelete =CommonType.Delete.NO;
    }

    public int hashCode() {
	return this.id == null ? System.identityHashCode(this) : this.id.hashCode();
    }

    public boolean equals(Object obj) {
	if (this == obj) {
	    return true;
	}
	if (obj == null) {
	    return false;
	}
	if (getClass().getPackage() != obj.getClass().getPackage()) {
	    return false;
	}
	BaseEntity other = (BaseEntity) obj;
	if (this.id == null) {
	    if (other.getId() != null)
		return false;
	} else if (!this.id.equals(other.getId())) {
	    return false;
	}
	return true;
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}